package edu.cc321.test;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

/**
 * @author Carl
 * 
 *         2014-4-24
 */
public class Image {

	public static void download(String num, String imageurl) throws IOException {
		URL url = new URL(imageurl);
		File outFile = new File("E:/Pics/image/" + num + ".jpg");
		OutputStream os = new FileOutputStream(outFile);
		InputStream is = url.openStream();
		byte[] buff = new byte[1024];
		while (true) {
			int readed = is.read(buff);
			if (readed == -1) {
				break;
			}
			byte[] temp = new byte[readed];
			System.arraycopy(buff, 0, temp, 0, readed);
			os.write(temp);
		}
		is.close();
		os.close();
	}

	public static void main(String[] args) throws InterruptedException {
		for (int i = 300; i < 400; i++) {
			String url = "http://jwxt.zhongxi.cn/jwweb/_photo/Student/";
			long a = 201100000000l + i;
			url += (a + ".jpg");
			System.out.println(url);
			try {
				download(a + "", url);
			} catch (IOException e) {
				e.printStackTrace();
			}
			Thread.sleep(500);
		}
	}
}
